package xy.boot.condition.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class ClassOnCondition implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        // 定义一个布尔值
        boolean flag;
        try {
            // 通过反射找到fastjson的类
            Class<?> aClass = Class.forName("com.alibaba.fastjson.JSON");
            // 找到了则返回true
            flag = true;
        } catch (ClassNotFoundException e) {
            // 找不到则返回false
            flag = false;
        }
        return flag;
    }
}
